package com.grant.code.mapper;


import com.grant.code.pojo.User;
import org.apache.ibatis.annotations.*;

public interface UserMapper {
    /**
     * 用户登录
     * @param user
     * @return
     */
    @Select("select * from user where user_name=#{userName} AND user_password=#{userPassword}")
    User login(User user);

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where user_name = #{username}")
    User getByUserName(String username);

    /**
     * 注册
     * @param user
     */
    @Insert("insert into user(user_name,user_password,user_role,user_status,user_hiredate) values(#{userName},#{userPassword},#{userRole},#{userStatus},#{userHiredate})")
    void register(User user);

    /**
     * 更新用户头像
     * @param userId
     * @param avatarPath
     */
    @Update("update user set user_avatar = #{avatarPath} where user_id = #{userId}")
    void updateUserAvatar(Integer userId, String avatarPath);

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where user_id = #{userId}")
    User getUserById(Integer userId);


    /**
     * 更新用户
     * @param updatedUser
     */
    @Update("update user set user_name = #{userName},user_password = #{userPassword},user_role = #{userRole},user_status = #{userStatus},user_hiredate = #{userHiredate} where user_id = #{userId}")
    void updateUser(User updatedUser);
}